#include<iostream>
#include<cstring>
#include<stack>
using namespace std;

char ch[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
stack<char> ans;

int main(){
	int n,m;
	cin>>n>>m;
	for(;;){
		ans.push(ch[n%m]);
		n = n/m;
		if(n<m){
			ans.push(ch[n%m]);
			break;
		}
	}
	
	while(!ans.empty()){
		cout<<ans.top();
		ans.pop();
	} 
	
	return 0;
}
